home *** CD-ROM | disk | FTP | other *** search
/ Digital Background Bonanza / Digital Background Bonanza - Disc 1.iso / pc / DBB1.swf / scripts / __Packages / mx / controls / listclasses / SelectableRow.as < prev   
Encoding:
Text File  |  2007-03-09  |  11.1 KB  |  370 lines

  1. class mx.controls.listclasses.SelectableRow extends mx.core.UIComponent
  2. {
  3.    var __height;
  4.    var cell;
  5.    var owner;
  6.    var rowIndex;
  7.    var icon_mc;
  8.    var __width;
  9.    var backGround;
  10.    var highlight;
  11.    var highlightColor;
  12.    var listOwner;
  13.    var item;
  14.    var isChangedToSelected;
  15.    var bGTween;
  16.    var grandOwner;
  17.    static var LOWEST_DEPTH = -16384;
  18.    var state = "normal";
  19.    var disabledColor = 15263976;
  20.    var normalColor = 16777215;
  21.    function SelectableRow()
  22.    {
  23.       super();
  24.    }
  25.    function setValue(itmObj, state)
  26.    {
  27.       var _loc7_ = this.__height;
  28.       var _loc2_ = this.cell;
  29.       var _loc5_ = this.owner;
  30.       var _loc8_ = this.itemToString(itmObj);
  31.       if(_loc2_.getValue() != _loc8_)
  32.       {
  33.          _loc2_.setValue(_loc8_,itmObj,state);
  34.       }
  35.       var _loc4_ = _loc5_.getPropertiesAt(this.rowIndex + _loc5_.__vPosition).icon;
  36.       if(_loc4_ == undefined)
  37.       {
  38.          _loc4_ = _loc5_.__iconFunction(itmObj);
  39.          if(_loc4_ == undefined)
  40.          {
  41.             _loc4_ = itmObj[_loc5_.__iconField];
  42.             if(_loc4_ == undefined)
  43.             {
  44.                _loc4_ = _loc5_.getStyle("defaultIcon");
  45.             }
  46.          }
  47.       }
  48.       var _loc3_ = this.icon_mc;
  49.       if(_loc4_ != undefined && itmObj != undefined)
  50.       {
  51.          _loc3_ = this.createObject(_loc4_,"icon_mc",20);
  52.          _loc3_._x = 2;
  53.          _loc3_._y = (_loc7_ - _loc3_._height) / 2;
  54.          _loc2_._x = 4 + _loc3_._width;
  55.       }
  56.       else
  57.       {
  58.          _loc3_.removeMovieClip();
  59.          _loc2_._x = 2;
  60.       }
  61.       var _loc9_ = _loc3_ != undefined ? _loc3_._width : 0;
  62.       _loc2_.setSize(this.__width - _loc9_,Math.min(_loc7_,_loc2_.getPreferredHeight()));
  63.       _loc2_._y = (_loc7_ - _loc2_._height) / 2;
  64.    }
  65.    function size(Void)
  66.    {
  67.       var _loc3_ = this.backGround;
  68.       var _loc2_ = this.cell;
  69.       var _loc4_ = this.__height;
  70.       var _loc5_ = this.__width;
  71.       var _loc6_ = this.icon_mc != undefined ? this.icon_mc._width : 0;
  72.       _loc2_.setSize(_loc5_ - _loc6_,Math.min(_loc4_,_loc2_.getPreferredHeight()));
  73.       _loc2_._y = (_loc4_ - _loc2_._height) / 2;
  74.       this.icon_mc._y = (_loc4_ - this.icon_mc._height) / 2;
  75.       _loc3_._x = 0;
  76.       _loc3_._width = _loc5_;
  77.       _loc3_._height = _loc4_;
  78.       this.drawRowFill(_loc3_,this.normalColor);
  79.       this.drawRowFill(this.highlight,this.highlightColor);
  80.    }
  81.    function setCellRenderer(forceSizing)
  82.    {
  83.       var _loc3_ = this.owner.__cellRenderer;
  84.       var _loc4_ = undefined;
  85.       if(this.cell != undefined)
  86.       {
  87.          _loc4_ = this.cell._x;
  88.          this.cell.removeMovieClip();
  89.          this.cell.removeTextField();
  90.       }
  91.       var _loc2_ = undefined;
  92.       if(_loc3_ == undefined)
  93.       {
  94.          var _loc0_ = null;
  95.          _loc2_ = this.cell = this.createLabel("cll",0,{styleName:this});
  96.          _loc2_.styleName = this.owner;
  97.          _loc2_.selectable = false;
  98.          _loc2_.tabEnabled = false;
  99.          _loc2_.background = false;
  100.          _loc2_.border = false;
  101.       }
  102.       else if(typeof _loc3_ == "string")
  103.       {
  104.          _loc2_ = this.cell = this.createObject(_loc3_,"cll",0,{styleName:this});
  105.       }
  106.       else
  107.       {
  108.          _loc2_ = this.cell = this.createClassObject(_loc3_,"cll",0,{styleName:this});
  109.       }
  110.       _loc2_.owner = this;
  111.       _loc2_.listOwner = this.owner;
  112.       _loc2_.getCellIndex = this.getCellIndex;
  113.       _loc2_.getDataLabel = this.getDataLabel;
  114.       if(_loc4_ != undefined)
  115.       {
  116.          _loc2_._x = _loc4_;
  117.       }
  118.       if(forceSizing)
  119.       {
  120.          this.size();
  121.       }
  122.    }
  123.    function getCellIndex(Void)
  124.    {
  125.       return {columnIndex:0,itemIndex:this.owner.rowIndex + this.listOwner.__vPosition};
  126.    }
  127.    function getDataLabel()
  128.    {
  129.       return this.listOwner.labelField;
  130.    }
  131.    function init(Void)
  132.    {
  133.       super.init();
  134.       this.tabEnabled = false;
  135.    }
  136.    function createChildren(Void)
  137.    {
  138.       this.setCellRenderer(false);
  139.       this.setupBG();
  140.       this.setState(this.state,false);
  141.    }
  142.    function drawRow(itmObj, state, transition)
  143.    {
  144.       this.item = itmObj;
  145.       this.setState(state,transition);
  146.       this.setValue(itmObj,state,transition);
  147.    }
  148.    function itemToString(itmObj)
  149.    {
  150.       if(itmObj == undefined)
  151.       {
  152.          return " ";
  153.       }
  154.       var _loc2_ = this.owner.__labelFunction(itmObj);
  155.       if(_loc2_ == undefined)
  156.       {
  157.          _loc2_ = !(itmObj instanceof XMLNode) ? itmObj[this.owner.__labelField] : itmObj.attributes[this.owner.__labelField];
  158.          if(_loc2_ == undefined)
  159.          {
  160.             _loc2_ = " ";
  161.             if(typeof itmObj == "object")
  162.             {
  163.                for(var _loc4_ in itmObj)
  164.                {
  165.                   if(_loc4_ != "__ID__")
  166.                   {
  167.                      _loc2_ = itmObj[_loc4_] + ", " + _loc2_;
  168.                   }
  169.                }
  170.                _loc2_ = _loc2_.substring(0,_loc2_.length - 2);
  171.             }
  172.             else
  173.             {
  174.                _loc2_ = itmObj;
  175.             }
  176.          }
  177.       }
  178.       return _loc2_;
  179.    }
  180.    function setupBG(Void)
  181.    {
  182.       var _loc0_ = null;
  183.       var _loc2_ = this.backGround = this.createEmptyMovieClip("bG_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH);
  184.       this.drawRowFill(_loc2_,this.normalColor);
  185.       this.highlight = this.createEmptyMovieClip("tran_mc",mx.controls.listclasses.SelectableRow.LOWEST_DEPTH + 10);
  186.       _loc2_.owner = this;
  187.       _loc2_.grandOwner = this.owner;
  188.       _loc2_.onPress = this.bGOnPress;
  189.       _loc2_.onRelease = this.bGOnRelease;
  190.       _loc2_.onRollOver = this.bGOnRollOver;
  191.       _loc2_.onRollOut = this.bGOnRollOut;
  192.       _loc2_.onDragOver = this.bGOnDragOver;
  193.       _loc2_.onDragOut = this.bGOnDragOut;
  194.       _loc2_.useHandCursor = false;
  195.       _loc2_.trackAsMenu = true;
  196.       _loc2_.drawRect = this.drawRect;
  197.       this.highlight.drawRect = this.drawRect;
  198.    }
  199.    function drawRowFill(mc, newClr)
  200.    {
  201.       mc.clear();
  202.       mc.beginFill(newClr);
  203.       mc.drawRect(1,0,this.__width,this.__height);
  204.       mc.endFill();
  205.       mc._width = this.__width;
  206.       mc._height = this.__height;
  207.    }
  208.    function setState(newState, transition)
  209.    {
  210.       var _loc2_ = this.highlight;
  211.       var _loc8_ = this.backGround;
  212.       var _loc4_ = this.__height;
  213.       var _loc3_ = this.owner;
  214.       if(!_loc3_.enabled)
  215.       {
  216.          if(newState == "selected" || this.state == "selected")
  217.          {
  218.             this.highlightColor = _loc3_.getStyle("selectionDisabledColor");
  219.             this.drawRowFill(_loc2_,this.highlightColor);
  220.             _loc2_._visible = true;
  221.             _loc2_._y = 0;
  222.             _loc2_._height = _loc4_;
  223.          }
  224.          else
  225.          {
  226.             _loc2_._visible = false;
  227.             this.normalColor = _loc3_.getStyle("backgroundDisabledColor");
  228.             this.drawRowFill(_loc8_,this.normalColor);
  229.          }
  230.          this.cell.__enabled = false;
  231.          this.cell.setColor(_loc3_.getStyle("disabledColor"));
  232.       }
  233.       else
  234.       {
  235.          this.cell.__enabled = true;
  236.          if(transition && (newState == this.state || newState == "highlighted" && this.state == "selected"))
  237.          {
  238.             this.isChangedToSelected = true;
  239.             return undefined;
  240.          }
  241.          var _loc6_ = _loc3_.getStyle("selectionDuration");
  242.          var _loc7_ = 0;
  243.          if(this.isChangedToSelected && newState == "selected")
  244.          {
  245.             transition = false;
  246.          }
  247.          var _loc10_ = transition && _loc6_ != 0;
  248.          if(newState == "normal")
  249.          {
  250.             _loc7_ = _loc3_.getStyle("color");
  251.             this.normalColor = this.getNormalColor();
  252.             this.drawRowFill(_loc8_,this.normalColor);
  253.             if(_loc10_)
  254.             {
  255.                _loc6_ /= 2;
  256.                _loc2_._height = _loc4_;
  257.                _loc2_._width = this.__width;
  258.                _loc2_._y = 0;
  259.                this.bGTween = new mx.effects.Tween(this,_loc4_ + 2,_loc4_ * 0.2,_loc6_,5);
  260.             }
  261.             else
  262.             {
  263.                _loc2_._visible = false;
  264.             }
  265.             delete this.isChangedToSelected;
  266.          }
  267.          else
  268.          {
  269.             this.highlightColor = _loc3_.getStyle(newState != "highlighted" ? "selectionColor" : "rollOverColor");
  270.             this.drawRowFill(_loc2_,this.highlightColor);
  271.             _loc2_._visible = true;
  272.             _loc7_ = _loc3_.getStyle(newState != "highlighted" ? "textSelectedColor" : "textRollOverColor");
  273.             if(_loc10_)
  274.             {
  275.                _loc2_._height = _loc4_ * 0.5;
  276.                _loc2_._y = (_loc4_ - _loc2_._height) / 2;
  277.                this.bGTween = new mx.effects.Tween(this,_loc2_._height,_loc4_ + 2,_loc6_,5);
  278.                var _loc9_ = _loc3_.getStyle("selectionEasing");
  279.                if(_loc9_ != undefined)
  280.                {
  281.                   this.bGTween.easingEquation = _loc9_;
  282.                }
  283.             }
  284.             else
  285.             {
  286.                _loc2_._y = 0;
  287.                _loc2_._height = _loc4_;
  288.             }
  289.          }
  290.          this.cell.setColor(_loc7_);
  291.       }
  292.       this.state = newState;
  293.    }
  294.    function onTweenUpdate(val)
  295.    {
  296.       this.highlight._height = val;
  297.       this.highlight._y = (this.__height - val) / 2;
  298.    }
  299.    function onTweenEnd(val)
  300.    {
  301.       this.onTweenUpdate(val);
  302.       this.highlight._visible = this.state != "normal";
  303.    }
  304.    function getNormalColor(Void)
  305.    {
  306.       var _loc3_ = undefined;
  307.       var _loc2_ = this.owner;
  308.       if(!this.owner.enabled)
  309.       {
  310.          _loc3_ = _loc2_.getStyle("backgroundDisabledColor");
  311.       }
  312.       else
  313.       {
  314.          var _loc5_ = this.rowIndex + _loc2_.__vPosition;
  315.          if(this.rowIndex == undefined)
  316.          {
  317.             _loc3_ = _loc2_.getPropertiesOf(this.item).backgroundColor;
  318.          }
  319.          else
  320.          {
  321.             _loc3_ = _loc2_.getPropertiesAt(_loc5_).backgroundColor;
  322.          }
  323.          if(_loc3_ == undefined)
  324.          {
  325.             var _loc4_ = _loc2_.getStyle("alternatingRowColors");
  326.             if(_loc4_ == undefined)
  327.             {
  328.                _loc3_ = _loc2_.getStyle("backgroundColor");
  329.             }
  330.             else
  331.             {
  332.                _loc3_ = _loc4_[_loc5_ % _loc4_.length];
  333.             }
  334.          }
  335.       }
  336.       return _loc3_;
  337.    }
  338.    function invalidateStyle(propName)
  339.    {
  340.       this.cell.invalidateStyle(propName);
  341.       super.invalidateStyle(propName);
  342.    }
  343.    function bGOnPress(Void)
  344.    {
  345.       this.grandOwner.pressFocus();
  346.       this.grandOwner.onRowPress(this.owner.rowIndex);
  347.    }
  348.    function bGOnRelease(Void)
  349.    {
  350.       this.grandOwner.releaseFocus();
  351.       this.grandOwner.onRowRelease(this.owner.rowIndex);
  352.    }
  353.    function bGOnRollOver(Void)
  354.    {
  355.       this.grandOwner.onRowRollOver(this.owner.rowIndex);
  356.    }
  357.    function bGOnRollOut(Void)
  358.    {
  359.       this.grandOwner.onRowRollOut(this.owner.rowIndex);
  360.    }
  361.    function bGOnDragOver(Void)
  362.    {
  363.       this.grandOwner.onRowDragOver(this.owner.rowIndex);
  364.    }
  365.    function bGOnDragOut(Void)
  366.    {
  367.       this.grandOwner.onRowDragOut(this.owner.rowIndex);
  368.    }
  369. }
  370.